package game

import (
	"time"
	"math/rand"
)

func randAPosition(maxX int, maxY int) *Point {
	rand.Seed(time.Now().UnixNano())
	return &Point{ X: rand.Intn(maxX - 3) + 3, Y: rand.Intn(maxY - 3) + 3, }
}

func genFood(maxX int, maxY int) *Food {
	p := randAPosition(maxX, maxY)
	p.PType = PointOfFood
	//log.L.Debug("gen new food", zap.Int("x", p.X), zap.Int("y", p.Y))
	return &Food{ Position: p }
}

func canChangeDirection(pre Direction, now Direction) bool {
	switch {
	case pre == Up && now == Down:
		return false
	case pre == Down && now == Up:
		return false
	case pre == Left && now == Right:
		return false
	case pre == Right && now == Left:
		return false
	}
	return true
}
